﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_BbsManage_TopicManageEdit : Baimasoft.Web.UI.PageFormTop 
{
    CMods MyCM = new CMods();
    Articles MyAT = new Articles();

    protected override void InitForm()
    {
        if (!Page.IsPostBack)
        {
            SectionNameDrpBind();
            try
            {
                string sEditStatus = this.Request.QueryString["EditStatus"].ToString().Trim();
                if (sEditStatus == "2")
                {
                    string sID = this.Request.QueryString["ID"].ToString().Trim();
                    SqlDataReader MySDR = MyAT.ReadArticleInfos("a.ArticleID =" + sID);
                    if (MySDR.Read())
                    {
                        SectionNameDrp.Text = MySDR["SectionID"].ToString().Trim();
                        Title.Text = MySDR["Title"].ToString().Trim();
                        Author.Text = MySDR["Author"].ToString().Trim();

                        PulishTime.Text = MySDR["PulishTime"].ToString().Trim();
                        STopDrp.Text = MySDR["STop"].ToString().Trim();

                        PrideDrp.Text = MySDR["Pride"].ToString().Trim();
                        Pots.Text = MySDR["Pots"].ToString().Trim();
                        sApproveResultDrp.Text = MySDR["sApproveResult"].ToString().Trim();
                        Content.Text = MySDR["Content"].ToString().Trim();
                    }
                }
            }
            catch
            {
            }
        }
    }

    public void SectionNameDrpBind()
    {
        SectionNameDrp.DataSource = MyCM.GetCModsInfo("a.Visiable='1'");
        SectionNameDrp.DataBind();
        SectionNameDrp.Items.Insert(0, "请选择");
        SectionNameDrp.Items[0].Value = "0";
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string sSectionID = SectionNameDrp.SelectedValue .ToString ().Trim ();
        string sTitle = Title.Text.ToString().Trim();
        string sAuthor = Author.Text .ToString().Trim();
        string sPulishTime = PulishTime.Text.ToString().Trim();
        string sSTopDrp = STopDrp.SelectedValue .ToString().Trim();

        string sPrideDrp = PrideDrp.SelectedValue.ToString().Trim();
        int ssApproveResultDrp = int.Parse (sApproveResultDrp.SelectedValue.ToString().Trim());
        string sPots = Pots.Text.ToString ().Trim ();
        string sContent = Content.Text.ToString().Trim();

        string UserIP = Request.UserHostAddress;
        string UserDNS = Request.UserHostName;

        if (this.EditStatus == EditStatus.Add)
        {
            int iback = MyAT.AddNewTopic(sSectionID, sTitle, sContent, sAuthor, UserIP, UserDNS, ssApproveResultDrp, sSTopDrp, sPrideDrp, sPots);
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('保存成功!');window.location.href='TopicManageList.aspx';</script>");
                return;
            }
        }
        else
        {
            DateTime UpDt = DateTime.Now;
            int iback = MyAT.UpdateTopic(sSectionID, sAuthor, sTitle, sContent, UserIP, UserDNS, ssApproveResultDrp, sSTopDrp, sPrideDrp, sPots, this.Request.QueryString["ID"].ToString().Trim());
            if (iback > 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功!');window.location.href='TopicManageList.aspx';</script>");
                return;
            }
        }
    }
}
